package com.ruoyi.btlfbreed.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.btlfbreed.domain.TbChickens;
import com.ruoyi.btlfbreed.service.ITbChickensService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 肉鸡Controller
 * 
 * @author codeman
 * @date 2024-05-05
 */
@RestController
@RequestMapping("/btlfbreed/chickens")
public class TbChickensController extends BaseController
{
    @Autowired
    private ITbChickensService tbChickensService;

    /**
     * 查询肉鸡列表
     */
    @PreAuthorize("@ss.hasPermi('btlfbreed:chickens:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbChickens tbChickens)
    {
        startPage();
        List<TbChickens> list = tbChickensService.selectTbChickensList(tbChickens);
        return getDataTable(list);
    }

    /**
     * 导出肉鸡列表
     */
    @PreAuthorize("@ss.hasPermi('btlfbreed:chickens:export')")
    @Log(title = "肉鸡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbChickens tbChickens)
    {
        List<TbChickens> list = tbChickensService.selectTbChickensList(tbChickens);
        ExcelUtil<TbChickens> util = new ExcelUtil<TbChickens>(TbChickens.class);
        util.exportExcel(response, list, "肉鸡数据");
    }

    /**
     * 获取肉鸡详细信息
     */
    @PreAuthorize("@ss.hasPermi('btlfbreed:chickens:query')")
    @GetMapping(value = "/{chickenId}")
    public AjaxResult getInfo(@PathVariable("chickenId") Long chickenId)
    {
        return success(tbChickensService.selectTbChickensByChickenId(chickenId));
    }

    /**
     * 新增肉鸡
     */
    @PreAuthorize("@ss.hasPermi('btlfbreed:chickens:add')")
    @Log(title = "肉鸡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbChickens tbChickens)
    {
        return toAjax(tbChickensService.insertTbChickens(tbChickens));
    }

    /**
     * 修改肉鸡
     */
    @PreAuthorize("@ss.hasPermi('btlfbreed:chickens:edit')")
    @Log(title = "肉鸡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbChickens tbChickens)
    {
        return toAjax(tbChickensService.updateTbChickens(tbChickens));
    }

    /**
     * 删除肉鸡
     */
    @PreAuthorize("@ss.hasPermi('btlfbreed:chickens:remove')")
    @Log(title = "肉鸡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chickenIds}")
    public AjaxResult remove(@PathVariable Long[] chickenIds)
    {
        return toAjax(tbChickensService.deleteTbChickensByChickenIds(chickenIds));
    }
}
